
/* SekiOS - io.c
 *
 * I/O helper functions
 *
 * Footnote: See io.h
 *
 * credit: Napalm
 */


/* input byte from port */
unsigned char
inportb (unsigned short port)
{
  unsigned char rv;
__asm__ ("inb %1, %0": "=a" (rv):"d" (port));
  return rv;
}

/* input word from port */
unsigned short
inportw (unsigned short port)
{
  unsigned short rv;
__asm__ ("inw %1, %0": "=a" (rv):"d" (port));
  return rv;
}

/* input dword from port */
unsigned long
inportl (unsigned short port)
{
  unsigned long rv;
__asm__ ("inl %1, %0": "=a" (rv):"d" (port));
  return rv;
}

/* input string of words from port */
void
inportsw (unsigned short port, void *buffer, int count)
{
  __asm__ ("cld; rep; insw"::"d" (port), "D" (buffer), "c" (count));
}

/* input string of dwords from port */
void
inportsl (unsigned short port, void *buffer, int count)
{
  __asm__ ("cld; rep; insl"::"d" (port), "D" (buffer), "c" (count));
}

/* output byte to port */
void
outportb (unsigned short port, unsigned char data)
{
  __asm__ ("outb %1, %0"::"d" (port), "a" (data));
}

/* output word to port */
void
outportw (unsigned short port, unsigned short data)
{
  __asm__ ("outw %1, %0"::"d" (port), "a" (data));
}

/* output dword to port */
void
outportl (unsigned short port, unsigned long data)
{
  __asm__ ("outl %1, %0"::"d" (port), "a" (data));
}

/* output string of words to port */
void
outportsw (unsigned short port, void *buffer, int count)
{
  __asm__ ("cld; rep; outsw"::"d" (port), "S" (buffer), "c" (count));
}

/* output string of dwords to port */
void
outportsl (unsigned short port, void *buffer, int count)
{
  __asm__ ("cld; rep; outsl"::"d" (port), "S" (buffer), "c" (count));
}
